Skip to content

src: fast path empty native immediate drain#62969

Open
gurgunday wants to merge 2 commits intonodejs:mainfrom
gurgunday:perf/env-skip-native-immediate
Open

src: fast path empty native immediate drain#62969
gurgunday wants to merge 2 commits intonodejs:mainfrom
gurgunday:perf/env-skip-native-immediate

Conversation

@gurgunday
Copy link
Copy Markdown
Member

@gurgunday gurgunday commented Apr 26, 2026

RunAndClearNativeImmediates is called from CheckImmediate on every event loop tick, but most calls have no native immediates queued

  • Add a fast path that checks the three queues that are drained here. If all three are empty, return before creating any V8 handles or scopes
  • Use the same check in CheckImmediate, along with a JS immediate existance check, to exit even earlier

Before:

./node benchmark/run.js --filter immediate.js --set type=depth --set n=5000000 timers
timers/immediate.js
timers/immediate.js type="depth" n=5000000: 77,957.7280919732

./node benchmark/run.js --filter immediate.js --set type=depth1 --set n=5000000 timers
timers/immediate.js
timers/immediate.js type="depth1" n=5000000: 78,239.25105583081

./node benchmark/run.js --filter set-immediate-depth-args.js --set n=5000000 timers
timers/set-immediate-depth-args.js
timers/set-immediate-depth-args.js n=5000000: 77,728.55421361701

After:

./node benchmark/run.js --filter immediate.js --set type=depth --set n=5000000 timers
timers/immediate.js
timers/immediate.js type="depth" n=5000000: 81,438.54733112443

./node benchmark/run.js --filter immediate.js --set type=depth1 --set n=5000000 timers
timers/immediate.js
timers/immediate.js type="depth1" n=5000000: 81,920.65230335212

./node benchmark/run.js --filter set-immediate-depth-args.js --set n=5000000 timers
timers/set-immediate-depth-args.js
timers/set-immediate-depth-args.js n=5000000: 80,653.84783982178

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Apr 26, 2026
@gurgunday gurgunday force-pushed the perf/env-skip-native-immediate branch from dc6cba4 to 0bed081 Compare April 26, 2026 11:55
@gurgunday gurgunday changed the title env: skip empty native immediate callback scope src: fast path empty native immediate drain Apr 26, 2026
@gurgunday gurgunday added the performance Issues and PRs related to the performance of Node.js. label Apr 26, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.65%. Comparing base (c202696) to head (1584afc).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62969      +/-   ##
==========================================
- Coverage   89.66%   89.65%   -0.02%     
==========================================
  Files         706      706              
  Lines      219416   219424       +8     
  Branches    42073    42077       +4     
==========================================
- Hits       196738   196718      -20     
- Misses      14576    14591      +15     
- Partials     8102     8115      +13     
Files with missing lines Coverage Δ
src/env.cc 85.31% <100.00%> (-0.22%) ⬇️
src/env.h 98.14% <ø> (ø)

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gurgunday gurgunday force-pushed the perf/env-skip-native-immediate branch from 0bed081 to 1584afc Compare April 26, 2026 13:38
@addaleax addaleax added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 27, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 27, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@gurgunday gurgunday added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants